// 简单工厂模式

function User (name, age, career, work) {
    this.name = name
    this.age = age
    this.career = career
    this.work = work
}
// 职业
const careerList = [
    {
        careerName: "产品",
        work: ["需求整理", "画原型", "产品把控"]
    },
    {
        careerName: "建筑",
        work: ["搬砖", "搅拌", "高空作业"]
    },
    {
        careerName: "程序猿",
        work: ["写代码", "修bug", "加班"]
    }
]
// 工厂函数
function Factory (name, age, career) {
    let work = [];
    const item = careerList.find(item => item.careerName === career)
    work = item.work || []
    return new User(name, age, career, work)
}

// 单个生产
const role1 = Factory("张三", 25, "产品")
console.log("role1", role1)

// 批量生产
// 模拟数据库数据
const userList = [
    {
        name: "张三",
        age: 30,
        careerName: "产品"
    },
    {
        name: "李四",
        age: 26,
        careerName: "建筑"
    },
    {
        name: "王五",
        age: 24,
        careerName: "程序猿"
    }
]

const userRole = userList.map(item => {
    return Factory(item.name, item.age, item.careerName)
})
console.log("userRole", userRole)